package com.example.logindemo.Service.Impl;

import com.example.logindemo.Mapper.UserMapper;
import com.example.logindemo.Pojo.User;
import com.example.logindemo.Service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public User getUser(String userName) {

        return userMapper.getUser(userName);
    }

    @Override
    public boolean addUser(User user) {
        user.setRole("common");
        return userMapper.addUser(user)>0 ? true : false;
    }

    @Override
    public boolean LoginByPhone(String phone) {
        return userMapper.selectByPhone(phone)!=null ? true : false;
    }

    @Override
    public User selectByPhone(String phone) {
        return userMapper.selectByPhone(phone);
    }

    @Override
    public boolean LoginByUserName(String userName) {
        return userMapper.selectByUserNameUser(userName)!=null ? true : false;
    }

    @Override
    public User selectByUserName(String userName) {
        return userMapper.selectByUserNameUser(userName);
    }

    @Override
    public String selectRoleByUserName(String userName) {
        return userMapper.selectRoleByUserName(userName);
    }
}
